<?php
/**
 * Created by PhpStorm.
 * User: xi
 * Date: 2020-05-02
 * Time: 16:54
 */

namespace app\api\service;


use app\admin\model\Air;
use app\admin\model\Assistant;
use app\admin\model\Roomclean;
use app\admin\model\Shopdevice;
use app\admin\model\Shoporderprofit;
use app\admin\model\Shoproombook;
use app\admin\model\Shopstaff;
use app\admin\model\Shoptable;
use app\admin\model\Userorderprofit;
use app\admin\model\Usertuan;
use app\admin\model\Userwithdraw;
use AlibabaCloud\SDK\Dyvmsapi\V20170525\Dyvmsapi;
use \Exception;
use AlibabaCloud\Tea\Exception\TeaError;
use AlibabaCloud\Tea\Utils\Utils;

use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\SDK\Dyvmsapi\V20170525\Models\SingleCallByTtsRequest;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;

class CallService
{

    public function call($order)
    {
        $config = new Config([
            // 必填，请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
            "accessKeyId" => "LTAI5tNJLYromU4zPm2fHhbz",
            // 必填，请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
            "accessKeySecret" => "cBqsbLHS4eAKDR5lATZ2378Ju557bT"
        ]);
        $config->endpoint = "dyvmsapi.aliyuncs.com";

        $assistAntModel = new Assistant();
        $ass = $assistAntModel->where('id',$order['assistant_id'])->find();

        $client = new Dyvmsapi($config);
        $name = $ass['name'];
        $singleCallByTtsRequest = new SingleCallByTtsRequest([
            "calledNumber" => $ass['mobile'],
            "ttsCode" => "TTS_302265081",
            "ttsParam" => "{\"name\":\".$name.\"}"
        ]);
        $runtime = new RuntimeOptions([]);
        try {
            // 复制代码运行请自行打印 API 的返回值
            $client->singleCallByTtsWithOptions($singleCallByTtsRequest, $runtime);
        } catch (Exception $error) {
            if (!($error instanceof TeaError)) {
                $error = new TeaError([], $error->getMessage(), $error->getCode(), $error);
            }
            // 此处仅做打印展示，请谨慎对待异常处理，在工程项目中切勿直接忽略异常。
            // 错误 message
            error_log($error->message);

        }
    }
}